package user_center.menu.controller;

import cwb.consts.RequestPrefix;
import cwb.dto.ResultData;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import user_center.menu.pojo.SystemMenu;
import user_center.menu.service.impl.SystemMenuServiceImpl;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Ezio.Auditore
 * Date: 2022-07-20
 * Time: 11:14
 *
 * @author Ezio.Auditore
 */
@RestController
@RequestMapping(RequestPrefix.API + "/system/menu")
@Api(value = "系统菜单", tags = "系统菜单", description = "系统菜单")
public class SystemMenuController {

    @Autowired
    private SystemMenuServiceImpl systemMenuService;

    /**
     * 菜单详情
     *
     * @param roleId
     * @return
     */
    @GetMapping("/detail")
    public ResultData detail(Integer roleId) {
        return ResultData.buildSucess(systemMenuService.getById(roleId));
    }

    /**
     * 列表查询
     *
     * @return
     */
    @GetMapping("/list")
    public ResultData list() {
        return ResultData.buildSucess(systemMenuService.list());
    }

    /**
     * 根据用户查询菜单
     *
     * @param userId
     * @return
     */
    @GetMapping("/getMenuUserList")
    public ResultData getMenuRoleList(Integer userId) {
        return ResultData.buildSucess(systemMenuService.getMenuRoleList(userId));
    }

    /**
     * 新增菜单
     *
     * @param systemMenuList
     * @return
     */
    @PutMapping("/addMenu")
    public ResultData addMenu(@RequestBody List<SystemMenu> systemMenuList) {
        return ResultData.buildSucess(systemMenuService.addMenu(systemMenuList));
    }

}
